//
//  BaseViewController.m
//  dogGroup
//
//  Created by iOS Two on 14-8-13.
//  Copyright (c) 2014年 iOS Two. All rights reserved.
//

#import "BaseViewController.h"
#import "Reachability.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
//    NSLog(@"uniqueIdentifier: %@", [[UIDevice currentDevice] identifierForVendor]);
//    NSLog(@"name: %@", [[UIDevice currentDevice] name]);
//    NSLog(@"systemName: %@", [[UIDevice currentDevice] systemName]);
//    NSLog(@"systemVersion: %@", [[UIDevice currentDevice] systemVersion]);
//    NSLog(@"model: %@", [[UIDevice currentDevice] model]);
//    NSLog(@"localizedModel: %@", [[UIDevice currentDevice] localizedModel]);
//    version = [[[UIDevice currentDevice] systemVersion] floatValue];//判断当前系统的版本号
    // Do any additional setup after loading the view.
}
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {
    CGRect rect = CGRectMake ( 0, 0, size.width, size.height);
    UIGraphicsBeginImageContext (rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor ( context, color.CGColor);
    CGContextFillRect (context,rect);
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext ();
    UIGraphicsEndImageContext ();
    return img;
}
//开始检查网络
-(BOOL)netWorkCheck {
    BOOL Wife = ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus) == ReachableViaWiFi;
    BOOL Gprs = ([Reachability reachabilityForInternetConnection].currentReachabilityStatus) == ReachableViaWWAN;
    if(Wife || Gprs) {
        return YES;
    } else {
        return NO;
    }
}

-(void)alertViewShow:(NSString *)text {
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:text delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)clearAllUIWebViewData {
    // Clear the webview cache...
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    //    [self removeApplicationLibraryDirectoryWithDirectory:@"Caches"];
    [self removeApplicationLibraryDirectoryWithDirectory:@"WebKit"];
    // Empty the cookie jar...
    for (NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
        [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
    }
    [self removeApplicationLibraryDirectoryWithDirectory:@"Cookies"];
}

- (void)removeApplicationLibraryDirectoryWithDirectory:(NSString *)dirName {
    NSString *dir = [[[[NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, NSUserDomainMask, YES) lastObject] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Library"] stringByAppendingPathComponent:dirName];
    if ([[NSFileManager defaultManager] fileExistsAtPath:dir]) {
        [[NSFileManager defaultManager] removeItemAtPath:dir error:nil];
    }
}

- (void)showIndeterminateProgress {
    if (HUD == nil) {
       	HUD = [[MBProgressHUD alloc]initWithView:self.view];
    }
    [self.view addSubview:HUD];
    [self.view bringSubviewToFront:HUD];
    HUD.delegate = self;
    [HUD show:YES];
}


@end
